package com.java1234.jxc.controller.admin;

import com.java1234.jxc.beans.GoodsUnit;
import com.java1234.jxc.service.GoodsUnitService;
import org.nutz.dao.Cnd;
import org.nutz.lang.Strings;
import org.nutz.lang.util.NutMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/admin/goodsUnit")
public class GoodsUnitController {

    @Autowired
    private GoodsUnitService goodsUnitService;

    /**
     * 返回所有商品单位 下拉框用到
     * @return
     * @throws Exception
     */
    @RequestMapping("/comboList")
    public Object comboList() throws Exception {
        List<GoodsUnit> goodsUnits = goodsUnitService.query(Cnd.where(null));
        return goodsUnits;
    }

    /**
     * 查询所有商品单位信息
     * @return
     */
    @RequestMapping("/listAll")
    public Object listAll(){
        NutMap result = NutMap.NEW();
        List<GoodsUnit> goodsUnits = goodsUnitService.query(Cnd.where(null));
        result.put("rows",goodsUnits);
        return result;
    }

    @RequestMapping("/save")
    public Object save(GoodsUnit goodsUnit){
        NutMap result = NutMap.NEW();
        if (goodsUnit.getId()!=null){
            goodsUnitService.update(goodsUnit);
        }else{
            goodsUnitService.insert(goodsUnit);
        }
        result.put("success",true);
        return result;
    }

    @RequestMapping("/delete")
    public Object delete(Integer id){
        NutMap result = NutMap.NEW();
        goodsUnitService.delete(id);
        result.put("success",true);

        return result;
    }









}
